package com.lemon.springcloudstreamyuumi.service.impl;

import com.lemon.springcloudstreamyuumi.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**
 * @program: SpringBootZoo
 * @author: Mr.Young
 * @create: 2021/4/10 23:22
 **/
@EnableBinding({Source.class}) // 定义消息推送管道
public class MessageProviderImpl implements IMessageProvider {

    @Autowired
    private MessageChannel output; // 消息发送管道

    @Override
    public String send() {
        String uid = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(uid).build());
        System.out.println("***uid: " + uid);
        return uid;
    }
}
